const express=require("express")
const router=express.Router();
const pool=require("../pool");


//用户注册
router.post("/",(req,res)=>{
  //获取post请求的数据
  var obj=req.body;

  //验证密码、邮箱、手机是否为空
  var $upwd=obj.upwd;
  if(!$upwd){
    res.send({code:402,msg:'upwd required'});
	return;
  }
  // var $email=obj.email;
  // if(!$email){
  //   res.send({code:403,msg:'email required'});
	// return;
  // }
  var $phone=obj.phone;
  if(!$phone){
    res.send({code:404,msg:'phone required'});
	return;
  }
  //执行SQL语句，将注册的数据插入到xz_user数据表中，成功响应 {code:200,msg:'register suc'}
  pool.query('INSERT INTO yhc_user SET ?',[obj],(err,result)=>{
    if(err) throw err;
	//是否添加成功
	if(result.affectedRows>0){
	  res.send({code:200,msg:'register suc'});
	}
  });
})
module.exports=router;